package week1.day3;

import java.util.Scanner;

/**
 * @Author fengzihao
 * @Date 2024-04-17 15:31
 */
public class Mark {
    public static void main(String[] args) {
        double[] scores = new double[10];
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入十个评委的打分：");
        for (int i = 0; i < 10; i++) {
            scores[i] = scanner.nextDouble();
        }
        double max = getMaxFromArray(scores);
        double min = getMinFromArray(scores);
        double average = getAverageFromArray(scores, max, min);
        System.out.println("average = " + average);
    }

    public static double getMaxFromArray(double[] scores) {
        double max = scores[0];
        for (int i = 1; i < scores.length; i++) {
            if (scores[i] > max)
                max = scores[i];
        }
        return max;
    }

    public static double getMinFromArray(double[] scores) {
        double min = scores[0];
        for (int i = 1; i < scores.length; i++) {
            if (scores[i] < min)
                min = scores[i];
        }
        return min;
    }

    public static double getAverageFromArray(double[] scores, double max, double min) {
        double sum = 0;
        for (int i = 0; i < scores.length; i++) {
            sum += scores[i];
        }
        sum -= min;
        sum -= max;
        return sum / scores.length - 2;
    }
}
